//
//  WWNetRequest.m
//  WWNetworkHelper
//
//  Created by swift on 2017/7/28.
//  Copyright © 2017年 王家伟. All rights reserved.
//

#import "WWNetRequest.h"
#import "WWInterfaceConst.h"
#import "WWNetworkHelper.h"
#import "SVProgressHUD.h"

NSString *_HUDTitle = @"";
@implementation WWNetRequest

#pragma mark - 请求方法：可以在其它界面直接调用，解除其它界面复杂的网络解析操作。一行代码完成请求即可
//登录
+ (NSURLSessionTask *)fetchLoginWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kLogin];
    _HUDTitle = @"登录中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 首页
+ (NSURLSessionTask *)fetchHomeWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kHome];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 城市列表
+ (NSURLSessionTask *)fetchCityListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kCityList];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 用户类型
+ (NSURLSessionTask *)fetchUserTypeWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetUserType];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 发送验证码
+ (NSURLSessionTask *)fetchVerificationCodeWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kVerificationCode];
    _HUDTitle = @"发送验证码到您的手机";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 注册
+ (NSURLSessionTask *)fetchRegisterWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kRegister];
    _HUDTitle = @"正在注册您的信息!";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 重置密码
+ (NSURLSessionTask *)fetchPasswordResetWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kForgotPassword];
    _HUDTitle = @"正在重置您的密码!";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 商品详情页
+ (NSURLSessionTask *)fetchGoodsDetailWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetGoodsDetail];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 收藏
+ (NSURLSessionTask *)fetchAddCollectWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kAddCollect];
    _HUDTitle = @"收藏商品";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 取消收藏商品
+ (NSURLSessionTask *)fetchDeleteCollectWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kDeleteCollect];
    _HUDTitle = @"取消收藏中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 加入购物车
+ (NSURLSessionTask *)fetchAddCartWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kAddCart];
    _HUDTitle = @"加入购物车";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}

// 商品列表
+ (NSURLSessionTask *)fetchGoodsListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetGoodsList];
    _HUDTitle = @"数据请求中...";
    return [self getRequestWithURL:url parameters:parameters success:success failure:failure];
}

// 订单预览  index.php/home/AppCart/cart2
+ (NSURLSessionTask *)fetchOrderInfoWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetOrderInfo];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 生成订单
+ (NSURLSessionTask *)fetchCreateOrderWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kCreateOrder];
    _HUDTitle = @"正在生成订单...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 订单支付
+ (NSURLSessionTask *)fetchPayOrderWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kPayOrder];
    _HUDTitle = @"正在支付...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}

// 开店
+ (NSURLSessionTask *)fetchOpenShopWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kOpenShop];
    _HUDTitle = @"正在提交申请...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 店铺列表 (首页店铺,搜索店铺都用这个)
+ (NSURLSessionTask *)fetchShopListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetShopList];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}

// 我的流水
+ (NSURLSessionTask *)fetchCklsListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kCklsList];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 历史分红指数 
+ (NSURLSessionTask *)fetchFhzsListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kFhzsList];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 编辑银行卡
+ (NSURLSessionTask *)fetchEditBankCardWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kEditBankCard];
    _HUDTitle = @"正在提交数据...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 添加银行卡
+ (NSURLSessionTask *)fetchAddBankCardWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kAddBankCard];
    _HUDTitle = @"正在提交数据...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 店铺分类(开店)
+ (NSURLSessionTask *)fetchShopTypeWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetShopType];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 购物车列表
+ (NSURLSessionTask *)fetchCartListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kCartList];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 删除购物车
+ (NSURLSessionTask *)fetchDeleteCartWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kDeleteCart];
    _HUDTitle = @"删除商品中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 修改商品数量 ;
+ (NSURLSessionTask *)fetchModifyGoodsAmountWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kModifyGoodsAmount];
    _HUDTitle = @"商品数量更新中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 修改商品选中状态
+ (NSURLSessionTask *)fetchModifyGoodsSelectedStateWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kModifyGoodsSelectedState];
    _HUDTitle = @"商品状态更新中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 修改商店选中状态
+ (NSURLSessionTask *)fetchModifyShopSelectedStateWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kModifyShopSelectedState];
    _HUDTitle = @"商铺状态更新中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 修改购物车全选状态
+ (NSURLSessionTask *)fetchModifyShoppingCartAllStateWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kModifyShoppingCartAllState];
    _HUDTitle = @"商品状态更新中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}

// 分类列表
+ (NSURLSessionTask *)fetchCategoryWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetCategory];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 附近商店
+ (NSURLSessionTask *)fetchNearShopWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetNearShop];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 城市选择接口 ;
+ (NSURLSessionTask *)fetchAreacommitWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kAreacommit];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 店铺详情 ;
+ (NSURLSessionTask *)fetchShopDetailWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetShopDetail];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 申请成为创客
+ (NSURLSessionTask *)fetchApplyForMakeWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kApplyFormaker];
    _HUDTitle = @"正在提交申请...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 退出登录 ;
+ (NSURLSessionTask *)fetchLogoutWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kLogout];
    _HUDTitle = @"正在退出登录...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 修改个人信息 ;
+ (NSURLSessionTask *)fetchModifyProfileWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kModifyProfile];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 地址列表 ;
+ (NSURLSessionTask *)fetchAddressListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetAddressList];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 删除地址
+ (NSURLSessionTask *)fetchDeleteAddressWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kDeleteAddress];
    _HUDTitle = @"正在删除地址...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 设置为默认地址
+ (NSURLSessionTask *)fetchSetDefaultAddressWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kSetDefaultAddress];
    _HUDTitle = @"正在设为默认地址...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 地址获取
+ (NSURLSessionTask *)fetchOneAddressWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetOneAddress];
    _HUDTitle = @"正在获取地址...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 添加地址
+ (NSURLSessionTask *)fetchAddAddressWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kAddAddress];
    _HUDTitle = @"正在提交...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 修改地址
+ (NSURLSessionTask *)fetchEditAddressWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kEditAddress];
    _HUDTitle = @"修改中...";    
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 我的收益
+ (NSURLSessionTask *)fetchMyEarningsWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kMyEarnings];
    _HUDTitle = @"数据请求中...";
    NSLog(@"我的收益 url = %@", url);
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 收款记录 ;
+ (NSURLSessionTask *)fetchMyshopRecordWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetMyshopRecord];
    _HUDTitle = @"数据请求中...";
    NSLog(@"收款记录 ulr = %@", url);
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
//用户付款记录
+ (NSURLSessionTask *)fetchUserRecordWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetUserRecord];
    _HUDTitle = @"数据请求中...";
    NSLog(@"用户付款记录 ulr = %@", url);
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 提现 kSqtx;
+ (NSURLSessionTask *)fetchSqtxWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kSqtx];
    _HUDTitle = @"正在提交申请...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 提现记录
+ (NSURLSessionTask *)fetchSqtxListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kSqtxList];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 我的收藏
+ (NSURLSessionTask *)fetchCollectListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetCollectList];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 银行卡列表
+ (NSURLSessionTask *)fetchBankCardWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetBankCard];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 设置默认银行卡
+ (NSURLSessionTask *)fetchSetDefaultBankCardWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kSetDefaultBankCard];
    _HUDTitle = @"数据提交中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 删除银行卡
+ (NSURLSessionTask *)fetchDeleteBankCardWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kDeleteBankCard];
    _HUDTitle = @"正在删除...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 订单列表
+ (NSURLSessionTask *)fetchOrderListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetOrderList];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 修改密码
+ (NSURLSessionTask *)fetchChangePasswordWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kChangePassword];
    _HUDTitle = @"密码修改中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 我的推荐人 ;
+ (NSURLSessionTask *)fetchMyReferralWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kGetMyReferral];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 用户信息 ;
+ (NSURLSessionTask *)fetchUserInfoWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kUserInfo];
    _HUDTitle = @"数据请求中...";
    return [self getRequestWithURL:url parameters:parameters success:success failure:failure];
}
// 商户入驻;
+ (NSURLSessionTask *)fetchShopRegisterWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kShopRegister];
    _HUDTitle = @"正在申请中...";
    return [self getRequestWithURL:url parameters:parameters success:success failure:failure];
}
// 我的足迹 (浏览记录)
+ (NSURLSessionTask *)fetchBrowseRecordsWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kBrowseRecords];
    _HUDTitle = @"正在申请中...";
    return [self getRequestWithURL:url parameters:parameters success:success failure:failure];
}

// 获取物流单号
+ (NSURLSessionTask *)fetchLogisticsNumWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kLogisticsNum];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 获取物流信息
+ (NSURLSessionTask *)fetchLogisticsInfoWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kLogisticsInfo];
    _HUDTitle = @"数据请求中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 取消订单
+ (NSURLSessionTask *)fetchCancelOrderWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kCancelOrder];
    _HUDTitle = @"订单取消中...";
    NSLog(@"取消订单url = %@", url);
    return [self getRequestWithURL:url parameters:parameters success:success failure:failure];
//    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 删除订单
+ (NSURLSessionTask *)fetchDeleteOrderWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kDeleteOrder];
    _HUDTitle = @"订单删除中...";
    NSLog(@"删除订单url = %@", url);
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}
// 确认收货
+ (NSURLSessionTask *)fetchConfirmOrderWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kConfirmOrder];
    NSLog(@"删除订单url = %@", url);
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}


// 积分专区
+ (NSURLSessionTask *)fetchIntegralAreaWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kIntegralArea];
    _HUDTitle = @"数据获取中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}

// 商户订单查询
+ (NSURLSessionTask *)fetchShopkeeperOrderListWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kShopkeeperOrder];
    _HUDTitle = @"数据获取中...";
    NSLog(@"订单管理 url = %@", url);

    return [self getRequestWithURL:url parameters:parameters success:success failure:failure];
}

// 商户查询
+ (NSURLSessionTask *)fetchShopkeeperMessWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kShopMess];
    _HUDTitle = @"数据获取中...";
    NSLog(@"订单管理 url = %@", url);
    
    return [self getRequestWithURL:url parameters:parameters success:success failure:failure];
    
}

// 编辑店铺
+ (NSURLSessionTask *)fetchEditShopWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kEditShop];
    _HUDTitle = @"正在提交申请...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}

// 线下支付订单
+ (NSURLSessionTask *)fetchPayOffLineWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kPayOffLine];
    _HUDTitle = @"支付中...";
    NSLog(@"线下支付订单 url = %@", url);
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}

// 线下支付订单(二维码支付)
+ (NSURLSessionTask *)fetchPayOffLinePayTypeWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kPayOffLinePayType];
    _HUDTitle = @"支付中...";
    NSLog(@"线下支付信息 url = %@", url);
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
}

//订单详情
+ (NSURLSessionTask *)fetchOrderDetailWithParameters:(id)parameters  success:(WWRequestSuccess)success failure:(WWRequestFailure)failure{
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,KOrderDetail];
    _HUDTitle = @"获取中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
    
}
//获取商户绑定账号
+ (NSURLSessionTask *)fetchOrderBindcardWithParameters:(id)parameters  success:(WWRequestSuccess)success failure:(WWRequestFailure)failure{
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,KOrderBindcard];
    _HUDTitle = @"获取中...";
    return [self requestWithURL:url parameters:parameters success:success failure:failure];

}
#pragma mark - 图片上传 : 开店&个人头像
+ (NSURLSessionTask *)fetchUploadImgWithParameters:(id)parameters imgArr:(NSArray *)imgArr success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kUploadImg];

    _HUDTitle = @"图片上传中...";
    return [self uploadImgWithURL:url imgArr:imgArr parameters:parameters success:^(id response) {

    } failure:^(NSDictionary *error) {

    }];
}

#pragma mark - 推荐关系
+ (NSURLSessionTask *)fetchAppUserGetMakeWithUrl:(NSString *)url Parameters:(id)parameters  success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    
   return [self requestWithURL:url parameters:parameters success:success failure:failure];
    
}


#pragma mark -- 上传图片
+ (NSURLSessionTask *)uploadImgWithURL:(NSString *)url imgArr:(NSArray *)imgArr parameters:(NSDictionary *)parameter success:(WWRequestSuccess)success failure:(WWRequestFailure)failure {
    
    // 在请求之前你可以统一配置你请求的相关参数 ,设置请求头, 请求参数的格式, 返回数据的格式....这样你就不需要每次请求都要设置一遍相关参数
    if (_HUDTitle.length) {
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeCustom];
        [SVProgressHUD setBackgroundLayerColor:[UIColor clearColor]];
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
        [SVProgressHUD showWithStatus:_HUDTitle];
    }
    
    // 设置头部信息
    [self setHeaderInformation];
    
    
    return [WWNetworkHelper uploadImagesWithURL:url parameters:parameter name:@"file" images:imgArr fileNames:nil imageScale:0.5 imageType:@"jpeg" progress:^(NSProgress *progress) {
        
    } success:^(id responseObject) {
        NSLog(@"正面 responseObject = %@", responseObject);
   

    } failure:^(NSError *error) {
        NSLog(@"正面 error = %@", error);
        
    }];
}
/*
 /**
 *  上传单/多张图片
 *
 *  @param URL        请求地址
 *  @param parameters 请求参数
 *  @param name       图片对应服务器上的字段
 *  @param images     图片数组
 *  @param fileNames  图片文件名数组, 可以为nil, 数组内的文件名默认为当前日期时间"yyyyMMddHHmmss"
 *  @param imageScale 图片文件压缩比 范围 (0.f ~ 1.f)
 *  @param imageType  图片文件的类型,例:png、jpg(默认类型)....
 *  @param progress   上传进度信息
 *  @param success    请求成功的回调
 *  @param failure    请求失败的回调
 *
 *  @return 返回的对象可取消请求,调用cancel方法
 */
//+ (__kindof NSURLSessionTask *)uploadImagesWithURL:(NSString *)URL
//                                        parameters:(id)parameters
//                                              name:(NSString *)name
//                                            images:(NSArray<UIImage *> *)images
//                                         fileNames:(NSArray<NSString *> *)fileNames
//                                        imageScale:(CGFloat)imageScale
//                                         imageType:(NSString *)imageType
//                                          progress:(WWHttpProgress)progress
//                                           success:(WWHttpRequestSuccess)success
//                                           failure:(WWHttpRequestFailed)failure;
// */
/*
 配置好WWNetworkHelper各项请求参数,封装成一个公共方法,给以上方法调用,
 相比在项目中单个分散的使用WWNetworkHelper/其他网络框架请求,可大大降低耦合度,方便维护
 在项目的后期, 你可以在公共请求方法内任意更换其他的网络请求工具,切换成本小
 */

#warning 这里的POST跟GET记得抽取下
#pragma mark - 请求的公共方法 (默认POST请求)
+ (NSURLSessionTask *)requestWithURL:(NSString *)URL parameters:(NSDictionary *)parameter success:(WWRequestSuccess)success failure:(WWRequestFailure)failure
{
    // 在请求之前你可以统一配置你请求的相关参数 ,设置请求头, 请求参数的格式, 返回数据的格式....这样你就不需要每次请求都要设置一遍相关参数
    KMyLog(@"url:%@",URL);
    if (_HUDTitle.length) {  // _HUDTitle 是空就不要弹框
        
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeCustom];
        [SVProgressHUD setBackgroundLayerColor:[UIColor clearColor]];
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
        [SVProgressHUD showWithStatus:_HUDTitle];
    }

    // 设置头部信息
    [self setHeaderInformation];

    // 发起请求
    return [WWNetworkHelper POST:URL parameters:parameter success:^(id responseObject) {
        [SVProgressHUD dismiss];
//        NSLog(@"responseObject = %@", responseObject);
        if ([responseObject isKindOfClass:[NSHTTPURLResponse class]]) {
            //*
            NSDictionary *dict = [[NSDictionary alloc] init];
            failure(dict);
            return;
            //*/
        }
        
        // 1 -100
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            
            if ([[responseObject objectForKey:@"appid"]isEqualToString:@"wxcd7bdf0dbf4c2439"]) {
                if (success) {
                    success(responseObject);
                    return;
                }
            }
            
            NSNumber *num = [responseObject objectForKey:@"status"];
            if (num.intValue == 1) { // 请求成功
                if (success) {
                    success(responseObject);
                    return;
                }
            }else if (num.intValue == -100) { // token失效
                //需要重新登录了,清除当前的用户信息
                [QJUserInfo RemoveCurrentUser];
                
                //弹出登录界面
                [[NSNotificationCenter defaultCenter] postNotificationName:@"alertLoginView" object:nil];
                if (failure) {
                    failure(responseObject);
                    return;
                }
            }else { // 其他所有情况
                if (failure) {
                    [self tipWithTitle:responseObject];
                    failure(responseObject);
                    return;
                }
            }
        }
        
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
        NSLog(@"error = %@", error);
        NSLog(@"code = %d", error.code);
        if (error.code == 3840) {
            NSDictionary *dict = [NSDictionary dictionaryWithObjects:@[@"3840",@"数据格式错误!"] forKeys:@[@"code",@"msg"]];
            [self tipWithTitle:dict];
            failure(dict);
            return;
        }else if (error.code == -1004){
            NSDictionary *dict = [NSDictionary dictionaryWithObjects:@[@"-1004",@"无法连接到服务器!"] forKeys:@[@"code",@"msg"]];
            [self tipWithTitle:dict];
            failure(dict);
            return;
        }else{
            NSString *code = [NSString stringWithFormat:@"%ld",(long)error.code];
            NSDictionary *dict = [NSDictionary dictionaryWithObjects:@[code, error.localizedDescription] forKeys:@[@"code", @"msg"]];
//            [self tipWithTitle:dict];
            failure(dict);
            return;
        }
    }];
}

+ (NSURLSessionTask *)getRequestWithURL:(NSString *)URL parameters:(NSDictionary *)parameter success:(WWRequestSuccess)success failure:(WWRequestFailure)failure
{
    // 在请求之前你可以统一配置你请求的相关参数 ,设置请求头, 请求参数的格式, 返回数据的格式....这样你就不需要每次请求都要设置一遍相关参数
    if (_HUDTitle.length) {
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeCustom];
        [SVProgressHUD setBackgroundLayerColor:[UIColor clearColor]];
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
        [SVProgressHUD showWithStatus:_HUDTitle];
    }
    
    // 设置头部信息
    [self setHeaderInformation];
    
    // 发起请求
    return [WWNetworkHelper GET:URL parameters:parameter success:^(id responseObject) {
        [SVProgressHUD dismiss];
        //        NSLog(@"responseObject = %@", responseObject);
        if ([responseObject isKindOfClass:[NSHTTPURLResponse class]]) {
            //*
            NSDictionary *dict = [[NSDictionary alloc] init];
            failure(dict);
            return;
            //*/
        }
        
        // 1 -100
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSNumber *num = [responseObject objectForKey:@"status"];
            if (num.intValue == 1) { // 请求成功
                if (success) {
                    success(responseObject);
                    return;
                }
            }else if (num.intValue == -100) { // token失效
                //需要重新登录了,清除当前的用户信息
                [QJUserInfo RemoveCurrentUser];
                
                //弹出登录界面
                [[NSNotificationCenter defaultCenter] postNotificationName:@"alertLoginView" object:nil];
                if (failure) {
                    failure(responseObject);
                    return;
                }
            }else { // 其他所有情况
                if (failure) {
                    [self tipWithTitle:responseObject];
                    failure(responseObject);
                    return;
                }
            }
        }
        
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
        NSLog(@"error = %@", error);
        NSLog(@"code = %d", error.code);
        if (error.code == 3840) {
            NSDictionary *dict = [NSDictionary dictionaryWithObjects:@[@"3840",@"数据格式错误!"] forKeys:@[@"code",@"msg"]];
            [self tipWithTitle:dict];
            failure(dict);
            return;
        }else if (error.code == -1004){
            NSDictionary *dict = [NSDictionary dictionaryWithObjects:@[@"-1004",@"无法连接到服务器!"] forKeys:@[@"code",@"msg"]];
            [self tipWithTitle:dict];
            failure(dict);
            return;
        }else{
            NSString *code = [NSString stringWithFormat:@"%ld",(long)error.code];
            NSDictionary *dict = [NSDictionary dictionaryWithObjects:@[code, error.localizedDescription] forKeys:@[@"code", @"msg"]];
            [self tipWithTitle:dict];
            failure(dict);
            return;
        }
    }];
}
//修改支付宝账户
+ (NSURLSessionTask *)ModifyApayWithParameters:(id)parameters success:(WWRequestSuccess)success failure:(WWRequestFailure)failure{
    
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kModifyApay];
    _HUDTitle = @"正在提交...";
    NSLog(@"线下支付订单 url = %@", url);
    return [self requestWithURL:url parameters:parameters success:success failure:failure];
    
}
+ (void)setHeaderInformation {
    // 头部信息
    // 时间戳
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval a = [dat timeIntervalSince1970];
    NSString *timeString = [NSString stringWithFormat:@"%.0f", a];
    // token
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    NSString *tokenStr = model.token ? model.token : @"";
    NSLog(@"tokenStr = %@", tokenStr);
    NSNumber *lastlogin = model.last_login ? model.last_login : 0;
    NSString *lastloginStr = [NSString stringWithFormat:@"%@", lastlogin];
    // 设置头部信息
    AFHTTPRequestSerializer *requestSerializer =  [AFHTTPRequestSerializer serializer];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:tokenStr forKey:@"token"];       // 用户token
    [dic setObject:lastloginStr forKey:@"lastlogin"];// 最后登录时间
    [dic setObject:@"" forKey:@"signalture"];       // 签名验证字符串 （加密规则待定）
    [dic setObject:@"ios" forKey:@"devicetype"];    // 设备号 （android，ios等）
    [dic setObject:timeString forKey:@"timestamp"]; // 时间戳
    
    if (dic != nil) {
        for (NSString *httpHeaderField in dic.allKeys) {
            NSString *value = dic[httpHeaderField];
            [requestSerializer setValue:value forHTTPHeaderField:httpHeaderField];
        }
    }
    [WWNetworkHelper setAFHTTPRequestSerializer:requestSerializer];
}

// 如果后台没有给出提示, 这里前端给出提示
+ (void)tipWithTitle:(id)response {  // QJNetworkManager 传过来的response 一定要是字典类型
    
    NSString *title = [response objectForKey:@"msg"];
    if ([title isKindOfClass:[NSString class]]) {
        if (title.length) {
            if ([title isEqualToString:@"未发现店铺!"]) {
                return;
            }
            [MBPHUD showAlertWithTitle:title];
            
        }else {
            
            [MBPHUD showAlertWithTitle:@"网络异常, 请稍后再试!"];
        }
    }else{
        return;
    }
   
}


@end
